Skip to content

refactor(line): use official LINE Bot SDK v8#2413

Open
ex-takashima wants to merge 1 commit intosipeed:mainfrom
ex-takashima:refactor/line-sdk
Open

refactor(line): use official LINE Bot SDK v8#2413
ex-takashima wants to merge 1 commit intosipeed:mainfrom
ex-takashima:refactor/line-sdk

Conversation

@ex-takashima
Copy link
Copy Markdown
Contributor

📝 Description

Replace hand-rolled HTTP/HMAC/JSON code (~270 lines) in the LINE channel with the official line-bot-sdk-go v8, reducing maintenance burden and eliminating potential bugs in signature verification, request construction, and response parsing.

This continues the work from #500 by @xiaket, which has been inactive for over a month. With @yinwm's encouragement (#500 (review)), I've rebased onto current main and addressed all review feedback.

🗣️ Type of Change

  • 🐞 Bug fix
  • ✨ New feature
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written

Changes

  • Replace bytes/crypto/encoding/json/io imports with line-bot-sdk-go/v8
  • Use webhook.ParseRequest for body reading + signature verification
  • Use messaging_api.MessagingApiAPI for ReplyMessage/PushMessage/ShowLoadingAnimation/GetBotInfo
  • Type-switch on webhook.MessageEvent message types (TextMessageContent, ImageMessageContent, etc.)
  • Type-switch on webhook.SourceInterface (UserSource/GroupSource/RoomSource)
  • Type-switch on webhook.Mentionee (UserMentionee/AllMentionee)

Net change: +174 / −295 lines in pkg/channels/line/line.go.

Review feedback addressed (from #500)

Issue Reviewer Fix
Context lost in API calls @yinwm Use WithContext(ctx) on all SDK calls
Variable shadowing of isMentioned @yinwm Declared at function scope, set inside switch
reflect-based message ID extraction @nikolasdehor / @yinwm Use type switch + msg.Id directly
Body size limit conflict with #1413 @yinwm Wrap r.Body with http.MaxBytesReader before webhook.ParseRequest; check for *http.MaxBytesError to return 413
Mention detection Use mentionee.IsSelf (new SDK field) for cleaner bot detection

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • All existing tests pass without modification (go test ./pkg/channels/line/...)
  • Rebased onto current main

Test plan

  • go build ./pkg/channels/line/
  • go test ./pkg/channels/line/ -v — 5/5 tests pass
  • Cross-compile for linux/arm64 works
  • Verify on real LINE bot in staging

Notes

Replace hand-rolled HTTP/HMAC/JSON code (~270 lines) with the official
line-bot-sdk-go v8, reducing maintenance burden and eliminating potential
bugs in signature verification, request construction, and response parsing.

This continues the work started in sipeed#500 by @xiaket, addressing all review
feedback and rebasing onto current main.

Changes:
- Replace bytes/crypto/json/io imports with line-bot-sdk-go/v8
- Use webhook.ParseRequest for body reading + signature verification
- Use messaging_api.MessagingApiAPI for ReplyMessage/PushMessage/ShowLoadingAnimation/GetBotInfo
- Type-switch on webhook.MessageEvent message types (TextMessageContent,
  ImageMessageContent, etc.) instead of JSON unmarshalling
- Type-switch on webhook.SourceInterface (UserSource/GroupSource/RoomSource)
- Type-switch on webhook.Mentionee (UserMentionee/AllMentionee)

Review feedback addressed (from sipeed#500):
- Use WithContext(ctx) on all SDK calls to preserve cancellation/timeout
- Fix variable shadowing of isMentioned (declared at function scope)
- Remove reflect-based message ID extraction (use type switch + msg.Id)
- Use mentionee.IsSelf for cleaner bot mention detection
- Preserve body size security check via http.MaxBytesReader before
  webhook.ParseRequest (compatible with sipeed#1413)

All existing tests pass without modification.
@sipeed-bot sipeed-bot bot added domain: channel go Pull requests that update go code dependencies Pull requests that update a dependency file labels Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file domain: channel go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant